package com.zhoutao123.hephaestus.object.bussiness;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.github.pagehelper.PageInfo;
import com.zhoutao123.hephaestus.repository.entity.Blog;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@EqualsAndHashCode(callSuper = true)
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class VBlogs extends PageBeanInfo implements Serializable {

  private List<VBlog> list;

  public static VBlogs of(PageInfo<Blog> pageInfo) {
    VBlogs vBlogs = new VBlogs();
    vBlogs
        .setEndRow(pageInfo.getEndRow())
        .setStartRow(pageInfo.getStartRow())
        .setHasNextPage(pageInfo.isHasNextPage())
        .setHasPreviousPage(pageInfo.isHasPreviousPage())
        .setFristPage(pageInfo.isIsFirstPage())
        .setLastPage(pageInfo.isIsLastPage())
        .setNextPage(pageInfo.getNextPage())
        .setPrePage(pageInfo.getPrePage())
        .setPageNum(pageInfo.getPageNum())
        .setPageSize(pageInfo.getPageSize())
        .setTotal(pageInfo.getTotal())
        .setPages(pageInfo.getPages());
    vBlogs.setList(pageInfo.getList().stream().map(VBlog::of).collect(Collectors.toList()));
    return vBlogs;
  }
}
